//
//  MessageCell.m
//  PigMarket
//
//  Created by mac on 2019/3/23.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "MessageCell.h"

@interface MessageCell ()
/**
 iconImg
 */
@property (nonatomic , strong) UIImageView *iconImgView;

/**
 messageNumLab
 */
@property (nonatomic , strong) UILabel *messageNumLab;

/**
 titleLab
 */
@property (nonatomic , strong) UILabel *titleLab;

/**
 timeLab
 */
@property (nonatomic , strong) UILabel *timeLab;

/**
 detailLab
 */
@property (nonatomic , strong) UILabel *detailLab;
@end
@implementation MessageCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *identifierID = @"identifierID";
    MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierID];
    if (cell == nil) {
        cell = [[MessageCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifierID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}
#pragma mark - init method
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self.contentView addSubview:self.iconImgView];
    [self.iconImgView addSubview:self.messageNumLab];
    [self.contentView addSubview:self.titleLab];
    [self.contentView addSubview:self.timeLab];
    [self.contentView addSubview:self.detailLab];
}

- (void)initLayout {
    // 布局子控件
    [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(20);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
    [self.messageNumLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.iconImgView.mas_left).offset(39);
        make.bottom.mas_equalTo(self.iconImgView.mas_bottom).offset(-35);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.iconImgView.mas_right).offset(20);
        make.top.mas_equalTo(10);
        make.width.mas_equalTo(100);
    }];
    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.top.mas_equalTo(12);
        make.left.mas_equalTo(self.titleLab.mas_right).offset(10);
    }];
    [self.detailLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.iconImgView.mas_right).offset(20);
        make.bottom.mas_equalTo(-14);
        make.right.mas_equalTo(-20);
    }];
}

#pragma mark - getter and setter
- (void)setInfoDic:(NSDictionary *)infoDic {
    _infoDic = infoDic;
    self.iconImgView.image = [UIImage imageNamed:infoDic[@"icon"]];
    self.messageNumLab.text = infoDic[@"messageNum"];
    self.titleLab.text = infoDic[@"title"];
    self.timeLab.text = infoDic[@"time"];
    self.detailLab.text = infoDic[@"detail"];
}
- (UIImageView *)iconImgView {
    if (!_iconImgView) {
        _iconImgView = [[UIImageView alloc] init];
        
    }
    return _iconImgView;
}
- (UILabel *)messageNumLab {
    if (!_messageNumLab) {
        _messageNumLab = [[UILabel alloc] init];
        _messageNumLab.textColor = [UIColor whiteColor];
        _messageNumLab.font = [UIFont smallFont];
        _messageNumLab.backgroundColor = [UIColor colorWithHexString:@"#EE5B5B"];
        _messageNumLab.textAlignment = NSTextAlignmentCenter;
        _messageNumLab.layer.cornerRadius = 10;
        _messageNumLab.layer.masksToBounds = YES;
    }
    return _messageNumLab;
}
- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.textColor = [UIColor textBlackColor];
        _titleLab.font = [UIFont largerFont];
    }
    return _titleLab;
}
- (UILabel *)timeLab {
    if (!_timeLab) {
        _timeLab = [[UILabel alloc] init];
        _timeLab.textColor = [UIColor colorWithHexString:@"#B0B0B0"];
        _timeLab.font = [UIFont smallFont];
        _timeLab.textAlignment = NSTextAlignmentRight;
    }
    return _timeLab;
}
- (UILabel *)detailLab {
    if (!_detailLab) {
        _detailLab = [[UILabel alloc] init];
        _detailLab.textColor = [UIColor colorWithHexString:@"#999999"];
        _detailLab.font = [UIFont middleFont];
    }
    return _detailLab;
}
@end
